package com.example.controller;

import com.example.interceptor.Auth;
import com.example.model.Course;
import com.example.model.Laboratory;
import com.example.service.LabService;
import com.example.util.DataMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: tao95
 * Date: 2017/5/11
 * Time: 11:42
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Auth
@Controller
@RequestMapping("lab")
@Api(value = "lab",tags = "实验室管理类")
public class LabController {

    @Autowired
    private LabService labServiceImpl;

    @RequestMapping(value = "/addLab",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.POST})
    @ApiOperation("添加实验室接口")
    public String  addAdmin(
            @ApiParam(name = "Laboratory",value = "实验室",required = true) Laboratory laboratory,
            HttpServletRequest request){
        ModelAndView model = new ModelAndView();

        DataMap dataMap = labServiceImpl.insertLab(laboratory);

        if((Integer)dataMap.get("code") == 10000){
            model.addObject("addLab","success");
        }else{
            model.addObject("addLab","Fail");
        }
        return "forward:/labList";
    }

    @RequestMapping(value = "/delLab",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.GET})
    @ApiOperation("删除实验室接口")
    public String  del1Lab(
            @ApiParam(name = "id",value = "实验室id",required = true) Integer id,
            HttpServletRequest request){
        ModelAndView model = new ModelAndView();
        DataMap dataMap = labServiceImpl.delLab(id);
        if((Integer)dataMap.get("code") == 10000){
            model.addObject("delLab","success");
        }else{
            model.addObject("delLab","Fail");
        }
        return "forward:/labList";
    }


}